package guestbook;

import java.io.IOException;
import javax.servlet.http.*;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

@SuppressWarnings("serial")
public class GuestbookServlet extends HttpServlet {
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		UserService userService = UserServiceFactory.getUserService();
		User user = userService.getCurrentUser();
		String url = null;
		if(user != null) {
			resp.setContentType("text/plain");
			resp.getWriter().println("Hello "+user.getNickname());
		} else {
			url = userService.createLoginURL
					(req.getRequestURI());
			resp.sendRedirect(url);
		}
		resp.getWriter().append("<a href=\" + userService.createLogoutUrl("/") + "\">Log out</a>");
			// resp.sendRedirect(userService.createLogoutURL("/guestbook"));
		
	}
}
